package com.nnnu.wsnackshop.listener;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.ImageData;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;

import java.util.List;

public class ImageDataConverter implements Converter<ImageData> {
    @Override
    public Class<ImageData> supportJavaTypeKey() {
        return ImageData.class;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.STRING;
    }

    @Override
    public ImageData convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
        // 读取时的转换（此处导出无需，可空实现）
        return null;
    }

    @Override
    public WriteCellData<?> convertToExcelData(ImageData value, ExcelContentProperty contentProperty,
                                               GlobalConfiguration globalConfiguration) {
        WriteCellData<?> cellData = new WriteCellData<>();
        cellData.setType(CellDataTypeEnum.STRING);
        cellData.setImageDataList(List.of(value));
        return cellData;
    }
}
